<?php

namespace App\Http\Controllers;

use App\Models\Newsletter;

class NewsletterController extends Controller
{
    function list() {
        $pn = request()->input('pn', config('api.page_num'));
        // $pn = 100;
        $city = request()->input('city', '');
        $city = rtrim($city, '0');
        if (strlen($city) % 2 === 1) {
            $city = $city . '0';
        }
        $city .= '%';

        $list = Newsletter::where([['city', 'like', $city]])
            ->paginate($pn);
        return response()->json(['recode' => 1,
            'data' => ['last_page' => $list->lastPage()
                , 'page' => $list->currentPage()
                , 'list' => $list->items()]]);

    }
}
